/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hoja7;

/**
 *
 * @author JJ
 */
public class Node<T>
{
   private int repet ;
    private String code;
    private T dato;
    private Node left;
    private Node  rigth;

    public Node(int preval, T dato) {
        this.repet = preval;
        this.dato = dato;
    }

    public Node(T dato) {
        this.dato = dato;
        this.repet = 1;
    }

    public Node() {
        this.repet = 0;
    }

    public int getRepet() {
        return repet;
    }

    public void setRepet(int preval) {
        this.repet = preval;
    }

    public void incRepet() {
        this.repet ++;
    }

    public T getDato() {
        return dato;
    }

    public void setDato(T dato) {
        this.dato = dato;
    }

    public Node getLeft() {
        return left;
    }

    public void setLeft(Node izq) {
        left = izq;
    }

    public Node getRigth() {
        return rigth;
    }

    public void setRigth(Node der) {
        rigth = der;
    }

    public String getCode() {
        return code;
    }
    
    @Override
    public String toString() {
        return ("" + getDato());
    }

    public void route(Node nodo, String codigo) {
        if(nodo != null) {
            if(nodo.getDato() != null)
                
                System.out.println("   "+nodo.getDato() + "     |      " + nodo.getRepet() +"      |   " + codigo);
            if(nodo.left != null) {
                code = codigo + "0";
                nodo.route(nodo.left, code);
                
            }
            if(nodo.rigth != null) {
                code = codigo + "1";
                nodo.route(nodo.rigth, code);

            }
      

        }
    }

    public void route() {
                   
            if(left != null) {
                code = "0";
                route(left, code);

            }
            if(rigth != null) {
                code = "1";
                route(rigth, code);

            }
       
    }
}
